Be careful not to use the Not operator with any data type other than Booleanespecially when youre using numbers that are something other than True or False values (-1 and 0, respectively). Consider the following code:
Sub cmdBool_Click ()
Dim intBool As Integer
Dim intTemp As Integer
intBool = True
Print intBool ' Prints -1
Print Not intBool ' Prints 0
intTemp = 5
Print intTemp ' Prints 5
Print Not intTemp ' Prints -6
If intTemp Then
Print "intTemp is True" ' Prints Here
Else
Print "intTemp is False"
End If
End Sub
Notice that the Not operator performs bitwise manipulation. Therefore, manipulating 5 actually makes it -6.
Use vbNullString Instead of an Empty String
The constant vbNullString is much more efficient that setting a string variable equal to an empty string (""):
strValue = ""
Use the following line of code instead:
strValue = vbNullString
This is an optimization thats built into the compiler. Therefore, instead of having to reallocate memory for the string, you can use a specific constant to set the memory equal to a null pointer and mark the rest of the memory allocated for the string to unused.